package com.cskaoyan.demo.servlet;

import com.cskaoyan.demo.mapper.AddressMapper;
import com.cskaoyan.demo.util.JsonUtil;
import com.cskaoyan.demo.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/")
public class AddressServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        AddressMapper mapper = sqlSession.getMapper(AddressMapper.class);

        int i = mapper.selectById(2);

        String json = JsonUtil.write(i);
        resp.getWriter().println(json);
    }
}
